﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model RedSand.Site.Models.NewsInfo
<!-- mvc javascript -->
<script src="/scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="/scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.form.js" type="text/javascript"></script>
<script src="/content/plugins/tiny-editor/tiny_mce/tiny_mce.js" type="text/javascript"></script>
<script src="/Scripts/rs.ajaxupload.js" type="text/javascript"></script>
<script type="text/javascript">
    tinyMCE.init({
        encoding: "xml",
        theme: "advanced",
        skin_variant: "silver",
        mode: "exact",
        elements: "News-content",
        skin: "default",
        width: "572",
        height: "250",
        relative_urls: false,
        theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,forecolor,backcolor,|,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2: "justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent,blockquote,charmap,|,cut,copy,paste,pastetext,pasteword,|,link,unlink,anchor,image,netImageBrowser,media,|,code",
        theme_advanced_buttons3: "",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left"
    });
    $(document).ready(function () {
        $('#choose-image').rsAjaxUpload({
            beforeSubmit: function (arr, form) {
                var filename = $.trim(form.find('input').val());
                var filefilter = ".jpg|.png|.bmp|.gif|.jpeg";
                var ext = filename.substring(filename.lastIndexOf('.')).toLowerCase();
                if (filefilter.indexOf(ext) < 0) {
                    alert("please choose image with extension : jpg, png, bmp, gif, jepg");
                    return false;
                }
                $('#Image').val(filename);
            },
            success: function (data) {
                if (data.indexOf('Error:') < 0) {
                    data = data.replace('&amp;', '&');
                    $('#imgThumbnai').attr('src', data);
                }
                else {
                    showMessage(data.replace('Error:', ''));
                }
            },
            error: function (data) {
                alert('file size too large');
                $('#imgThumbnai').attr('src', '');
            }
        });
    })
</script>
<div id="box-create">
    <h1>
        Create Post</h1>
    <div class="msg_error">
        @Html.Raw(ViewBag.msgError)
    </div>
    @using (Html.BeginForm("feCreate", "post", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.ValidationSummary(true)
        <div id="content-left">
            @Html.LabelFor(m => m.Title)
            @Html.TextBoxFor(m => m.Title)
            <div class="clr">
            </div>
            @Html.ValidationMessageFor(m => m.Title)
            @Html.LabelFor(m => m.Alias)
            @Html.TextBoxFor(m => m.Alias)
            <div class="clr">
            </div>
            @Html.ValidationMessageFor(m => m.Alias)
            @Html.LabelFor(m => m.CategoryID, "Category")
            @Html.DropDownListFor(m => m.CategoryID, (List<SelectListItem>)ViewBag.SelectListCategory, "-- Please select a category --")
            <div class="clr">
            </div>
            @Html.ValidationMessageFor(m => m.CategoryID)
            @Html.LabelFor(m => m.Description)
            @Html.TextAreaFor(m => m.Description, new { @id = "News-description" })
            <div class="clr">
            </div>
            @Html.ValidationMessageFor(m => m.Description)
        </div>
        <div id="box-preview">
            <img alt="Preview" id="imgThumbnai"  height="26px" width="26px" />
             @Html.ValidationMessageFor(m => m.Image)
            <a href="javascript:void(0)" id="choose-image"></a>
            <input type="text" name="Image" id="Image" />
        </div>
        <div class="clr">
        </div>
        @Html.TextAreaFor(m => m.Content, new { @id = "News-content" })
        <div class="clr">
        </div>
        @Html.ValidationMessageFor(m => m.Content)
        <input type="submit" class="btn" value="Save" />
    }
</div>
